package com.yifi.system.controller;

import cn.hutool.cron.CronUtil;
import com.jfinal.aop.Inject;
import com.jfinal.core.Path;
import com.yifi.common.base.BaseController;
import com.yifi.system.service.CronService;

/**
 * @author 姚善利
 * @classname com.yifi.system.controller
 * @description
 * @date 2022/12/6 14:18
 */
@Path(value="/sys_cron",viewPath = "/system/")
public class SysCronController extends BaseController {

    public void index()
    {
        render("sys_cron.html");
    }

    @Inject
    private CronService cronService;
    public void list()
    {
        int pageNum=getParaToInt("pageNum",1);
        int pageSize=getParaToInt("pageSize",10);
        String cname=getPara("cname","");
        renderJson(cronService.list(pageNum,pageSize,cname));
    }

    public void getData()
    {
        String id=getPara("id","");
        renderJson(cronService.getData("sys_cron","id",id));
    }

    public void save()
    {
        renderJson(cronService.save(this));
    }

    public void remove()
    {
        String ids=getPara("ids","");
        CronUtil.remove(ids);
        renderJson(cronService.removes("sys_cron","id",ids));
    }
    public void start()
    {
        String id=getPara("id","");
        renderJson(cronService.start(id));
    }
    public void stop()
    {
        String id=getPara("id","");
        renderJson(cronService.stop(id));
    }
}
